package com.qf.controller;

import com.qf.pojo.entity.QfCourse;
import com.qf.pojo.req.QfCourseReq;
import com.qf.pojo.resp.BaseResp;
import com.qf.service.QfCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/course")
@Api("课程信息控制层")
public class QfCourseController {
    @Autowired
    QfCourseService qfCourseService;
    @RequiresPermissions({"COURSE_FIND_ALL"})
    @ApiOperation(value = "查询所有课程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "当前页显示条数",required = true,dataType = "Integer")
    })
    @PostMapping("/findAll")
    public BaseResp findAll(@RequestParam("page")Integer page,@RequestParam("size")Integer size){
        return qfCourseService.findAll(page,size);
    }
    @RequiresPermissions({"COURSE_UPDATE_OR_SAVE"})
    @ApiOperation(value = "新增或修改课程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "qfCourseReq",value = "课程请求对象",required = true,dataType = "QfCourseReq")
    })
    @PostMapping("/updateOrSave")
    public BaseResp updateOrSave(@RequestBody QfCourseReq qfCourseReq){
        return qfCourseService.updateOrSave(qfCourseReq);
    }
    @RequiresPermissions({"COURSE_DELETE"})
    @ApiOperation(value = "删除课程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map",value = "删除的课程id",required = true,dataType = "Map")
    })
    @PostMapping("/deleteById")
    public BaseResp deleteById(@RequestBody Map map){
        return qfCourseService.deleteById(Integer.valueOf(map.get("id").toString()));
    }
}
